<template>
  <div>
    <div class="subject">
      <span>{{ one }}</span>
      <span>+</span>
      <span>{{ two }}</span>
      <span>=</span>
      <input type="number" v-model.number="num" />
      <button @click="totle(num)">提交</button>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      one: 0,
      two: 0,
      sum: 0,
      num: 0,
    };
  },
  mounted() {
    this.one = parseInt(Math.random() * 10 + 1);
    this.two = parseInt(Math.random() * 10 + 1);
    this.sum = this.one + this.two;
  },
  methods: {
    totle() {
      if (this.num === this.sum) {
        this.$emit("value", "回答正确", this.$attrs.id);
        // console.log(this.$attrs.id);
      } else {
        this.$emit("value", "回答错误", this.$attrs.id);
        // console.log(this.$attrs.id);
      }
    },
  },
};
</script>

<style scoped>
.subject {
  margin: 5px;
  padding: 5px;
  font-size: 20px;
}
.subject span {
  display: inline-block;
  text-align: center;
  width: 20px;
}
.subject input {
  width: 50px;
  height: 20px;
}
</style>
